home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / userbox / publicdomain / superplay-lib_dev / programmers / example_spobjects / st / sp_infosubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  4.0 KB  |  147 lines

  1.  
  2.  /* SP_InfoSubs.c
  3.     - Functions for ST-Support -
  4.     (c) 1994 by Andreas R. Kleinert
  5.     Last changes : 17.05.1994
  6.  */
  7.  
  8. #include "spobject.h"
  9.  
  10. #include <ctype.h>
  11.  
  12.  
  13.  /* PUBLIC functions (high level) */
  14.  
  15. ULONG __saveds __asm SPO_FileInfoRequest( register __a1 struct SPObjectHandle *SPObjectHandle_a1, register __a2 struct Window *window, register __a3 ULONG future);
  16. ULONG __saveds __asm SPO_CheckFileType(register __a1 BPTR handle, register __a2 UBYTE *filename, register __a3 APTR future);
  17. void  __saveds __stdargs SPLI_SPrintf(APTR buffer, char *formatstring, ...);
  18.  
  19.  
  20. /* *************************************************** */
  21. /* *                                                 * */
  22. /* * SPO_FileInfoRequest : Display File Information  * */
  23. /* *                                                 * */
  24. /* *************************************************** */
  25.  
  26. ULONG __saveds __asm SPO_FileInfoRequest( register __a1 struct SPObjectHandle *SPObjectHandle_a1, register __a2 struct Window *window, register __a3 ULONG future)
  27. {
  28.  struct SPObjectHandle *SPObjectHandle = SPObjectHandle_a1;
  29.  
  30.  ULONG retval = SPERR_NO_ERROR;
  31.  char buffer [2001], h_buf [80], hbuf2[5];
  32.  ULONG idcmp = N, noinfo = TRUE;
  33.  struct EasyStruct *estr;
  34.  struct Window     *disp_win = window;
  35.  
  36.  if(!SPObjectHandle) return(SPERR_NO_HANDLE);
  37.  
  38.  buffer[0] = (char) 0;
  39.  
  40.  if(SPObjectHandle->ah_STModule)
  41.   {
  42.    struct STHeader *STHeader = SPObjectHandle->ah_STModule;
  43.    UWORD i, j;
  44.  
  45.    noinfo = FALSE;
  46.  
  47.    strcat(buffer,   "\n File Information"
  48.                   "\n\n File Type : SoundTracker/ProTracker/NoiseTracker (ST)");
  49.  
  50.    strcat(buffer, "\n");
  51.  
  52.    strcat(buffer, "\n Module-Name    : ");
  53.    strcat(buffer, SPObjectHandle->ah_ReadName);
  54.  
  55.    strcat(buffer, "\n Module-Length  : ");
  56.    sprintf(h_buf, "%ld Bytes", SPObjectHandle->ah_STLen);
  57.    strcat(buffer, h_buf);
  58.  
  59.    strcat(buffer, "\n Module-Type    : ");
  60.  
  61.    strncpy(hbuf2, &STHeader->st_ID[0], 4);
  62.    hbuf2[4] = (UBYTE) 0;
  63.  
  64.    sprintf(h_buf, "%4s", hbuf2);
  65.    strcat(buffer, h_buf);
  66.  
  67.    strcat(buffer, "\n Song-Name      : ");
  68.    strcat(buffer, STHeader->st_SongName);
  69.  
  70.    for(i=0; i<31; i++) if(!STHeader->st_Instruments[i].st_InstrumentLength) { i++; break; }
  71.  
  72.    sprintf(h_buf, "\n %-2ld Instruments : \n\n ", i);
  73.    strcat(buffer, h_buf);
  74.  
  75.    for(i=j=0; j<31; j++)
  76.     {
  77.      if(isprint(STHeader->st_Instruments[j].st_InstrumentName[0]))
  78.       {
  79.        STHeader->st_Instruments[j].st_InstrumentName[21] = (UBYTE) 0;
  80.  
  81.        sprintf(h_buf, "\42%-21s\42  ", STHeader->st_Instruments[j].st_InstrumentName);
  82.        strcat(buffer, h_buf);
  83.  
  84.        if(!(++i % 3)) strcat(buffer, "\n ");
  85.       }
  86.     }
  87.  
  88.   }else retval = SPERR_NO_HANDLE;
  89.  
  90.  if(!retval)
  91.   {
  92.    if(noinfo)
  93.     {
  94.      strcat(buffer,   "\n File Information"
  95.                     "\n\n No information available\n");
  96.     }
  97.  
  98.    estr = AllocVec(sizeof(struct EasyStruct), MEMF_CLEAR);
  99.    if(estr)
  100.     {
  101.      estr->es_StructSize   = sizeof(struct EasyStruct);
  102.      estr->es_Flags        = N;
  103.      estr->es_Title        = "SuperPlay InfoRequester";
  104.      estr->es_TextFormat   = buffer;
  105.      estr->es_GadgetFormat = "Confirm";
  106.  
  107.      if(!disp_win) disp_win = SPObjectHandle->ah_ReqIOWindow;
  108.  
  109.      EasyRequestArgs(disp_win, estr, &idcmp, N);
  110.      FreeVec(estr);
  111.     }
  112.   }
  113.  
  114.  return(retval);
  115. }
  116.  
  117. /* *************************************************** */
  118. /* *                             * */
  119. /* * SPLI_CheckFileType : ...                    * */
  120. /* *                             * */
  121. /* *************************************************** */
  122.  
  123. ULONG __saveds __asm SPO_CheckFileType(register __a1 BPTR handle_a1, register __a2 UBYTE *filename, register __a3 APTR future)
  124. {
  125.  UBYTE *nameptr = filename;
  126.  
  127.  while(*nameptr)
  128.   {
  129.    if(*nameptr=='.')
  130.     {
  131.      if(!strnicmp("MOD.", nameptr-3, 4)) return(TRUE);
  132.      if(!strnicmp(".MOD", nameptr,   4)) return(TRUE);
  133.     }
  134.  
  135.    nameptr++;
  136.   }
  137.  
  138.  return(FALSE);
  139. }
  140.  
  141. extern void Fmt(void); /* Assembler-Routine for RawDoFmt */
  142.  
  143. void __saveds __stdargs SPLI_SPrintf(APTR buffer, char *formatstring, ...)
  144. {
  145.  RawDoFmt((APTR) formatstring, (APTR) (((ULONG *)&formatstring)+1), (APTR) &Fmt, (APTR) buffer);
  146. }
  147.